home *** CD-ROM | disk | FTP | other *** search
- From: richard@atheist.tamu.edu (Richard Henderson)
- Message-ID: <4ep4ii$l81@news.tamu.edu>
- X-Original-Date: 1 Feb 1996 01:21:22 GMT
- Path: in2.uu.net!bounce-back
- Date: 01 Feb 96 02:01:25 GMT
- Approved: fjh@cs.mu.oz.au
- Newsgroups: comp.std.c++
- Subject: Re: Cleaning auto_ptr copy semantics.
- Organization: Texas A&M University, College Station, TX
- References: <gregorDLrrun.K2x@netcom.com>
- Reply-To: rth@tamu.edu
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBFAgUBMRAfDuEDnX0m9pzZAQGPAgF/fOl65cXYULMKbnk4oOEsUURqaRkOuRrK
- e/6hTBpCfOUcX4DDQAah7DkBYoFfdGep
- =YWze
-
- In article <gregorDLrrun.K2x@netcom.com>,
- Greg Colvin <gregor@netcom.com> wrote:
- >The smallest change I can see that preserves the semantics of strict
- >ownership is to separate the concepts of "holding a pointer" and "owning
- >an object", so that more than one auto_ptr can hold a pointer to an object,
- >but only one auto_ptr can own the object.
-
- The problem I see with this is that a holder cannot see when
- an object goes away. With the old transfer of control semantics,
- there is never a dangling pointer to an object. Dangling pointers
- are, in my opinion, much more dangerous than NULL pointers.
-
- Also, I see no difference, wrt temporaries, between your solution
- and making "px" mutable. Both solutions actually change the temporary.
-
- >Note also that reset() must go, since the idiom p.reset(q.release())
- >cannot safely transfer ownership. I would happily remove get() as well,
- >since its primary use may turn out to be leaking pointers.
-
- Without get(), how do you (without moving to full reference counting,
- which I think should exist _along side of_ auto_ptr) pass
-
- auto_ptr<foo> a;
-
- to a function bar(), and retain control of the object after bar()
- terminates? The current
-
- extern void bar(foo *);
- bar(a.get());
-
- is quite satisfactory. On the other hand
-
- extern void bar(foo *);
- foo *tmp = a.release();
- bar(tmp);
- a.reset(tmp);
-
- violates one of the main reasons for having auto_ptr (cleaning up
- on the way out of an exception within bar()), and
-
- extern void bar(const auto_ptr<foo> &);
- bar(a);
-
- destroys a's object when bar returns (if nothing happens within
- bar() to cause it to be destroyed sooner) under both the original
- semantics and your revised semantics.
-
- > template<class Y> auto_ptr(const auto_ptr<Y>&); |
- > template<class Y> auto_ptr& operator=(const auto_ptr<Y>&); |
-
- I do like the template members though.
-
-
- r~
- ---
- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
- Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
- is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
-